import { houseSourceList } from '@/api/houseResource'

const houseSource = {
  state: {
    houseSourceDataList: [],
    houseParams: {
      // hoperatorId: '', // 经营者id
      storesId: '', // 门店id
      jylx: '', // 门店所属经营类型
      fwrzzt: 0, // 房屋状态
      fh: '' // 房号
    },
    houseLoading: false
  },
  mutations: {
    setHouseSourceList (state, data) {
      state.houseSourceDataList = data
    },
    setHouseParams (state, data) {
      state.houseParams = Object.assign(state.houseParams, data)
    },
    setHouseLoading (state, data) {
      state.houseLoading = data
    }
  },
  actions: {
    getHouseSourceList ({ commit }, data) {
      commit('setHouseLoading', true)
      return new Promise((resolve, reject) => {
        try {
          houseSourceList(data).then((res) => {
            const data = res
            commit('setHouseSourceList', data.data)
            setTimeout(() => {
              commit('setHouseLoading', false)
            }, 200)
            resolve(data)
          }).catch(error => reject(error))
        } catch (error) {
          reject(error)
        }
      })
    }
  }
}
export default houseSource
